package pers.xiaojun.boot.module.system.dao.mapper.dict;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import pers.xiaojun.boot.module.system.dao.entity.dict.DictDataDO;

import java.util.List;

/**
 * 字典数据数据访问层
 *
 * @author xiaojun
 * @since 2025-10-23
 */
@Mapper
public interface DictDataMapper extends BaseMapper<DictDataDO> {

    /**
     * 根据标签获取字典数据
     *
     * @param label 标签
     * @return 字典数据
     */
    default DictDataDO selectByLabel(String label) {
        return this.selectOne(new LambdaQueryWrapper<DictDataDO>()
                .eq(DictDataDO::getLabel, label)
        );
    }

    /**
     * 根据字典类型删除字典数据
     *
     * @param dictType 字典类型
     * @return 删除条目数
     */
    default int deleteByDictType(String dictType) {
        return delete(new LambdaQueryWrapper<DictDataDO>()
                .eq(DictDataDO::getDictType, dictType)
        );
    }

    /**
     * 根据字典类型删除一批字典数据
     *
     * @param dictTypes 字典类型列表
     * @return 删除条目数
     */
    default int deleteByDictTypes(List<String> dictTypes) {
        return delete(new LambdaQueryWrapper<DictDataDO>()
                .in(DictDataDO::getDictType, dictTypes)
        );
    }

}
